package com.hyfrogx.modules.manage.controller;

import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.manage.form.parameter.*;
import com.hyfrogx.modules.manage.service.HyGiveConfigService;
import com.hyfrogx.modules.manage.service.HyProductionVacuateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0.0
 * @Author: lfh
 * @Date: 2019/9/23 17:22
 * @Company 汉咏科技
 * 参数比例控制类
 */
@RestController
@RequestMapping("/system/param")
@Api(value = "HyProductionVacuateController", tags = {"后台--系统参数管理"})
public class HyProductionVacuateController {

    @Autowired
    private HyProductionVacuateService hyProductionVacuateService;
    @Autowired
    private HyGiveConfigService hyGiveConfigService;


    /**
     *  查询产品比例全部信息
     */
    @PostMapping("/get/product_scale")
    @ApiOperation("查询产品比例全部信息")
    public R getVacuate()
    {
        List<ProductionScaleVo> list = hyProductionVacuateService.getListProduct();
        return R.ok().put("list",list);
    }
    /**
     * 更改充值比例和注册赠送和产品抽成参数，
     * @rechargeForm  充值比例id，基础参数，充值比例
     */
    @PostMapping("update/recharge")
    @ApiOperation("更改充值比例和注册赠送和产品抽成参数")
    public R updateRecharge(@RequestBody @Validated VacuateForm vacuateForm)
    {
        Boolean b = hyProductionVacuateService.updateVacuateandRecharge(vacuateForm);
        if (b)
        {
            return R.ok();
        }
        else
        {
            return R.error("更新失败");
        }
    }


    /**
     * 查询转赠功能参数
     *
     */
    @PostMapping("/get/give_config")
    @ApiOperation("查询转赠功能参数")
    public R getGiveConfig()
    {
        GiveConfigVo giveConfigForm = hyGiveConfigService.getGiveOne();
        return R.ok().put("result",giveConfigForm);
    }

    /**
     * 更改转赠功能参数
     */
    @PostMapping("update/give_config")
    @ApiOperation("更改转赠功能参数")
    public R updateGiveConfig(@RequestBody @Validated GiveConfigForm giveConfigForm)
    {
        Boolean b = hyGiveConfigService.updateGiveConfig(giveConfigForm);
        if (b)
        {
            return R.ok();
        }
        else
        {
            return R.error("更新失败");
        }
    }


}
